/**
 * 统一工具函数和验证函数
 * 使用 cross-env-plugins 作为基础工具库
 */
import { utils, valids } from 'cross-env-plugins'

// 导出所有工具函数
export const {
  random,
  formatTime,
  getDayOfWeek,
  getTimeUntilEnd,
  formatCurrency,
  convertToChinese,
  generateRandomCode,
  randomStr,
  debounce,
  throttle,
  deepClone,
  mergeObjects,
  uniqueArray,
  checkPwd,
  getUrlParam,
  generateUUID,
  capitalize,
  camelCase,
  snakeCase,
  flattenArray,
  groupBy,
  paginate,
  getRelativeTime,
  getDaysDiff,
  isSameDay,
  formatFileSize,
  formatNumber,
  toPercent,
  base64Encode,
  base64Decode,
  urlEncode,
  urlDecode,
  truncate,
  deepEqual,
  getType,
  isType,
  add,
  subtract,
  multiply,
  divide
} = utils

// 导出所有验证函数
export const {
  isEmail,
  isMobile,
  validateIDCard,
  checkCode,
  isValidDate,
  convertTo18Digits,
  isURL,
  isIP,
  isBankCard,
  isChineseName,
  isPostalCode,
  isLicensePlate,
  isUnifiedSocialCreditCode,
  isNumber,
  isInteger,
  isDecimal,
  isEmpty,
  isLength,
  isPositiveInteger,
  isNonNegativeInteger,
  isChinese,
  isEnglish
} = valids

// 重新导出，方便使用
export { utils, valids }

/**
 * 格式化日期时间（兼容项目现有格式）
 * @param value 日期值
 * @param format 格式化字符串，默认为 'yyyy-MM-dd hh:mm:ss'
 * @returns 格式化后的日期字符串
 */
export const formatDateTime = (value: string | number | Date | null | undefined, format: string = 'yyyy-MM-dd hh:mm:ss'): string => {
  if (!value) return '-'
  try {
    // 将 number 转换为 Date 对象
    const date = typeof value === 'number' ? new Date(value) : value
    return formatTime(date, format)
  } catch {
    return '-'
  }
}

